package com.by.common.controller;

import com.by.common.bean.ResultBean;

public class BaseController {

    protected ResultBean success(String msg){
        return handler(ApiCode.SUCCESS,msg,null);
    }

    protected ResultBean success(String msg,Object data){
        return handler(ApiCode.SUCCESS,msg,data);
    }

    protected ResultBean fail(String msg){
        return handler(ApiCode.FAIL,msg,null);
    }

    protected ResultBean fail(String msg,Object data){
        return handler(ApiCode.FAIL,msg,data);
    }

    ResultBean handler(int code,String msg,Object data){
        return new ResultBean(code,msg,data);
    }

    protected ResultBean saveResult(int rs){
        return rs==1?success("保存成功"):fail("保存失败");
    }
    protected ResultBean updateResult(int rs){
        return rs==1?success("修改成功"):fail("修改失败");
    }
    protected ResultBean deleteResult(int rs){
        return rs==1?success("删除成功"):fail("删除失败");
    }
}
